$("#costDetail_CompanyTable").hide();
$("#costDetail_BranchTable").hide();
var module = $("#moduleHidden").val();
var costTemp = null;
$("span.currency-style-green").each(function(){
    costTemp = $.trim($(this).text());
	if(costTemp != ""){
		costTemp = $(this).text().replace(/,/g, "");
		costTemp = MZ.toDecimal(costTemp / MZ.CURRENCY_PRECISION, MZ.CURRENCY_ROUND);
		$(this).text(costTemp);
	}else{
		$(this).text("");
	}
});
//set cost detail
var costStr = "";

var otherCostDetail =  $("#otherDetail").val();
if($.trim(otherCostDetail) != ""){
	otherCostDetail = eval( "(" + otherCostDetail + ")" );
	var obj = null;
	for(var i in otherCostDetail){
		obj = otherCostDetail[i];
		costStr+= obj["name"]+":<font color='green'>"+obj["cost"]+"</font> &nbsp;";
	} 
}
$("#otherCostSPAN").html(costStr);

costStr = "";
var leaderDetail = $("#leaderDetail").val();
if($.trim(leaderDetail) != ""){
	leaderDetail = eval( "(" + leaderDetail + ")" );
	var obj = null;
	for(var i in leaderDetail){
		obj = leaderDetail[i];
		costStr+= obj["name"]+":<font color='green'>"+obj["cost"]+"</font> &nbsp;";
	} 
}
$("#leaderCostSPAN").html(costStr);

costStr = "";
var outputvalueDetail = $("#outputvalueDetail").val();
if($.trim(outputvalueDetail) != ""){
	outputvalueDetail = eval( "(" + outputvalueDetail + ")" );
	var obj = null;
	for(var i in outputvalueDetail){
		obj = outputvalueDetail[i];
		costStr+= obj["name"]+":<font color='green'>"+obj["cost"]+"</font> &nbsp;";
	} 
}
$("#outputvalueSPAN").html(costStr);


if(module == MZ.BRANCH_COST_VERIFY){
	$("#costDetail_BranchTable").show();
}else if(module == MZ.COMPANY_COST_VERIFY){
	$("#costDetail_CompanyTable").show();
}

var statusStr = "cancel";
//cancelBtn
$("#cancelBtn").bind("click", function(){
	statusStr = "cancel";
	var reason = "";
	jPrompt('请输入审核驳回原因:', '', '系统提示', function(r) {
	    if( r ) {
	    	reason = r;
	    	verifyCost(reason);
	    }
	});
});

$("#submitBtn").bind("click", function(){
	statusStr = "pass";
	verifyCost("");
});


function verifyCost(reason){
	var verifyId = $("#idHidden").val();
	var verifier = $("#verifierSel").val();
	if(verifier == null){
		verifier = "";
	}else if(verifier == ""){
		if(statusStr == "pass"){
			MZ.showMsg("请指定审核配置下一级的审核人!");
			return false;
		}
	}
	var params = {"id":verifyId,"statusStr":statusStr,"reason":reason,"verifier":verifier};
	$("#verifyDIV").hide();
	$.ajax({
		url : "verify/verifyCost",
		type : "post",
		data : params,
		beforeSend : function() {
		},
		success : function(result) {
			if(result.succeed){
				MZ.showMsg(result.message);
			}
			MZ.reloadDatagrid("msgDatagird");
		},
		error: function(result){
			MZ.showMsg(result);
		}
	});
}